rm(list = ls())

library(haven)
library(tidyverse)
## Load voting data

dat <- read_dta('data/voting_behavior.dta') %>%
  mutate(vote_deviate_bin = ifelse(vote_deviate == 2 | vote_deviate == 3, 1, 0),
         year = lubridate::year(vote_date))

## Average deviation per bill over time 

plot_df <- dat %>%
  group_by(year) %>%
  summarise(vote_deviate_bin = mean(vote_deviate_bin, na.rm = T))

## Plot This 

p1 <- ggplot(plot_df, aes(x = year, y = vote_deviate_bin)) + 
  geom_point() + 
  geom_smooth(se = F, col = 'black') + 
  theme_bw() + 
  labs(x = 'Year',
       y = 'Share of deviations from party line') + 
  scale_x_continuous(breaks = seq(1950, 2010, 5)) 

p1
